#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <GL/glut.h>
#include "MatVec.h"
#include "objects.h"
#include <time.h>
#include <iostream>
#include <vector>

#if defined(WIN32)
# include <conio.h>
#else
# include "conio.h"
#endif


#include <HD/hd.h>
#include <HDU/hduVector.h>
#include <HDU/hduError.h>
#include <HL/hl.h>
#include <HLU/hlu.h>

// id needed for haptic shape.
extern HLuint gMyShapeId;

using namespace std;

// The collection of spheres
extern vector< sphere > spheres;

// The six walls. Spheres and planes are defines in objects.h
extern plane walls[6];
extern double wall;
// Hitting 's' adds energy to the scene with some scaling as defined below. 
extern double shakemag;



extern int mode;
extern double beginx, beginy;

// Some stuff for allowing mouse rotations of the scene
extern double dis;
extern double azim;
extern double elev;
extern double ddis;
extern double dazim;
extern double delev;
extern double rot1;
extern double rot2;
extern double rot3;
extern int animate;

// The timestep of the simulation
extern double deltat;
extern double half_deltat;
// Number of spheres in the sim
extern int numspheres;
// Either do Euler or midpoint integration
extern bool euler;
// wall spring constant
extern double wall_spring;
// ball spring constant
extern double ball_spring;
// Define gravity vector
extern double gravity[];
// Define air friction scaling
extern double air_friction;


void
InitViewerWindow();

void
BeginDraw();

void
EndDraw();

void DrawSpheres();
void DrawWalls();

void computeForce( unsigned int i, double force[3] );

void
MouseCB(int _b, int _s, int _x, int _y);

void 
KeyboardCB(unsigned char key, int x, int y);

void
MotionCB(int _x, int _y);

void
DisplayCB();

void init(int argc, char **argv);

void init_walls(void);